import logging

# # 必须先配置，再输出日志
# # 设置全局日志级别为INFO
# logging.basicConfig(level=logging.INFO)

# logging.debug("this is a debug logging")
# logging.info("this is an info logging")
# logging.warning("this is a warning logging")
# logging.error("this is an error logging")
# logging.critical("this is a critical logging")

#
# # 针对全局
# logging.basicConfig(level=logging.INFO)
# # 获取日志记录器对象,名称为当前模块的名称
# # logger = logging.getLogger(__name__)
# logger = logging.getLogger("my_logging")
#
# # 针对日志记录器级别为DEBUG
# logger.setLevel(level=logging.DEBUG)
# logger.debug("this is a debug logging")
# logger.info("this is an info logging")
# logger.warning("this is a warning logging")
# logger.error("this is an error logging")
# logger.critical("this is a critical logging")

# 获取一个日志记录器对象logger,名称为当前模块的名称
logger = logging.getLogger("my_logger")

# 设置日志记录器的级别为DEBUG
# DEBUG级别及以上的日志都会被记录
logger.setLevel(level=logging.DEBUG)

# 创建一个FileHandler对象,指定日志文件的名称为"test.log"
# 创建的文件处理器会将日志写入到指定的文件中
handler = logging.FileHandler(filename="test.log")

# # 创建一个日志格式器对象
# formatter = logging.Formatter(
#     "%(asctime)s %(levelname)s [%(name)s] [%(filename)s (%(funcName)s:%(lineno)d)] - %(message)s"
# )
#
# # 将日志格式器添加到文件处理器中
# handler.setFormatter(formatter)

# 将文件处理器添加到日志记录器中
# 日志记录器就会使用这个文件处理器来处理日志信息
logger.addHandler(handler)

logger.debug("this is a debug logging")
logger.info("this is an info logging")
logger.warning("this is a warning logging")
logger.error("this is an error logging")
logger.critical("this is a critical logging")



